package cn.gov.cbrc.east.verify;

import java.sql.Connection;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cn.gov.cbrc.core.db.QueryRunnerUtil;
import cn.gov.cbrc.core.db.StoreManager;
import cn.gov.cbrc.east.task.Task;

/**
 * 项目名称：EastCheck<br>
 * *********************************<br>
 * <P>类名称：LoadFormula</P>
 * *********************************<br>
 * <P>类描述：校验公式装载</P>
 * 创建人：王川<br>
 * 创建时间：Jan 26, 2016 9:53:40 AM<br>
 * 修改人：王川<br>
 * 修改时间：Jan 26, 2016 9:53:40 AM<br>
 * 修改备注：<br>
 * @version 1.0<br>    
 */
public class LoadFormula {
	private static final Logger logger = LogManager.getLogger(LoadFormula.class);
	public static S_Table getTable(String tableCode){
		S_Table table = null;
		try{
			Connection conn = StoreManager.getConnection();
			QueryRunner query = QueryRunnerUtil.getInstance();
			String selectT = "select * from S_Table where _tableCode='"+tableCode+"';";
			String selectC = "select * from S_Column where _tableCode='"+tableCode+"' order by _colIndex;";
			String selectF;
			table = query.query(conn, selectT, new BeanHandler<S_Table>(S_Table.class));
			List<S_Column> cList = query.query(conn, selectC, new BeanListHandler<S_Column>(S_Column.class));
			if(null != table){
				table.set_columns(cList);
				for(S_Column col:cList){
					selectF = "select s._formula,s._formulaType from S_Formula s where _tableCode='"+tableCode+"'"+" and _colCode='"+col.get_colCode()+"'";
					col.set_verifies(query.query(conn, selectF, new BeanListHandler<S_Formula>(S_Formula.class)));
				}
			}
		}catch(Exception e){
			logger.error("sqlite查询出错",e);
		}finally{
			StoreManager.closeConnection();
		}
		return table;
	}
	
}
